<link rel="stylesheet" type="text/css" href="/public/static/css/index.css" />
<script src="/public/static/js/synchro.js"></script>
<{include file="tpl/filter.tpl"}>

<div>
    <a class="label-success pull-right" style="color: #fff; padding: 0 4px;" href="<{PubFunc::buildUrl('/oss/?r=routineCrossServer/add')}>">
        <i class="fa fa-plus"></i> 添加
    </a>&nbsp;
    <a href="javascript:;" style="color: #FFFFFF;padding-left: 3px;padding-right: 3px;margin-right: 15px;" id="force_view" name="force_view" class="label-success pull-right"  data-url="?r=routineCrossServer/forceView">查看强制性解除</a>
    <input class="label-success pull-left" type="checkbox" id="all" />&nbsp;<span id="aa">全选</span>
	<a href="javascript:;" id="relieve_batch" name="relieve_batch" class="btn" style="margin-right: 5px;margin-bottom: 5px;" data-url="?r=routineCrossServer/relieve">解除</a>
	<a href="javascript:;" id="rou_synchro_batch" name="rou_synchro_batch" class="btn" style="margin-right: 5px;margin-bottom: 5px;" data-url="?r=routineCrossServer/rouSynchro">同步</a>
	<a href="javascript:;" style="display: none;" id="force_relieve_batch" name="force_relieve_batch" class="btn" style="margin-right: 5px;margin-bottom: 5px;" data-url="?r=routineCrossServer/forcerelieve">强制性解除</a>
	<!--<a href="?r=routineCrossServer/automatic&g=mango">自动生成</a>-->
</div>

<{include file="tpl/grid.tpl"}>
	
	
<script>
	    /**批量解除**/
        $('a[name="relieve_batch"]').click(function(){
        	var arr = new Array();
        	var data_relieve_arr = new Array();
            $("input[name='id']:checkbox[checked]").each(function(i){
                arr[i] = $(this).val();
                data_relieve_arr[i] = $(this).attr('data-relieve');
            });
            
            var show_flag = true;
            var info = '序号为 ';
            for(i = 0; i < data_relieve_arr.length; i++) {
                if (data_relieve_arr[i] == 1) {
                	show_flag = false;
                	info += arr[i] + ', ';
                }
            }
            info = info.substr(0,info.length-2);
            info += ' 的数据不符合解除的条件';
            if(!show_flag){
                layer.alert(info, {icon: 2, skin: 'layui-layer-molv'});
            	return false;
            }
            
            var ids = arr.join(",");
            //console.log(ids);
            if(ids == ""){
            	layer.msg('请先选择要操作的数据！', {icon: 2,time: 3000});
            	return false;
            }
            relieve(ids);
        });
        
        /**单独解除**/
        $(document).on('click','a[name="relieve_one"]',function(){
        	var ids = $(this).attr('data-id');
        	if(ids == ""){
            	layer.msg('请先选择要操作的数据！', {icon: 2,time: 3000});
            	return false;
            }
        	relieve(ids);
        });
        
        function relieve(ids){       	
        	var loading = null;
        	layer.confirm('确定解除!', {
        			btn: ['确定','取消'] //按钮
        			,skin: 'layui-layer-molv'
        	}, function(){
        	        var data_url = $("#relieve_batch").attr('data-url');
                    var g = $("input[name='g']").val();
                    var url = data_url+'&g='+g;
                    uploading = layer.load(1, {shade: [0.4, '#393D49']});
                    $.ajax({
        	        	type : 'POST',
    			        url : url,
				        data : {'ids':ids},
				        dataType :'JSON',
				        success : function(res){
				        	layer.close(uploading);
				        	if(res.status == 1){
				        		layer.alert(res.msg, {
				        			skin: 'layui-layer-molv' //样式类名
						            ,closeBtn: 0
					            }, function(){
						             window.location.reload();
					            });	
				        		//layer.alert(res.msg, {skin: 'layui-layer-molv'});
					        }else{
						        layer.alert(res.msg, {icon: 2, skin: 'layui-layer-molv'});
					        }
				        }
			        });
                    
        	    }, function(){
        			//取消
        		});
        }
</script>

<script>
	    /**强制性解除**/
        $(document).on('click','a[name="force_relieve_one"]',function(){
        	var ids = $(this).attr('data-id');
        	if(ids == ""){
            	layer.msg('请先选择要操作的数据！', {icon: 2,time: 3000});
            	return false;
            }
        	forcerelieve(ids);
        });
        
        function forcerelieve(ids){       	
        	var loading = null;
        	layer.confirm('确定强制性解除!', {
        			btn: ['确定','取消'] //按钮
        			,skin: 'layui-layer-molv'
        	}, function(){
        	        var data_url = $("#force_relieve_batch").attr('data-url');
                    var g = $("input[name='g']").val();
                    var url = data_url+'&g='+g;
                    uploading = layer.load(1, {shade: [0.4, '#393D49']});
                    $.ajax({
        	        	type : 'POST',
    			        url : url,
				        data : {'ids':ids},
				        dataType :'JSON',
				        success : function(res){
				        	layer.close(uploading);
				        	if(res.status == 1){
				        		layer.alert(res.msg, {
				        			skin: 'layui-layer-molv' //样式类名
						            ,closeBtn: 0
					            }, function(){
						             window.location.reload();
					            });	
				        		//layer.alert(res.msg, {skin: 'layui-layer-molv'});
					        }else{
						        layer.alert(res.msg, {icon: 2, skin: 'layui-layer-molv'});
					        }
				        }
			        });
                    
        	    }, function(){
        			//取消
        		});
        }
</script>


<script>
	
	    /**批量同步**/
        $('a[name="rou_synchro_batch"]').click(function(){
        	var arr = new Array();
        	var show_status_arr = new Array();
    		var data_list_arr = new Array();
            $("input[name='id']:checkbox[checked]").each(function(i){
                arr[i] = $(this).val();
                show_status_arr[i] = $(this).attr('data-status');
                data_list_arr[i] = $(this).attr('data-list');
            });
            var ids = arr.join(",");
            
            var show_flag = true;
            var info = '状态须为 未同步 且 有包含服务器才可以进行同步，序号为 ';
            for(i = 0; i < show_status_arr.length; i++) {
                if (show_status_arr[i] == 2 || show_status_arr[i] == 5 || data_list_arr[i] == 2) {
                	show_flag = false;
                	info += arr[i] + ', ';
                }
            }
            info = info.substr(0,info.length-2);
            info += ' 的数据不符合同步的条件';
            if(!show_flag){
                layer.alert(info, {icon: 2, skin: 'layui-layer-molv'});
            	return false;
            }
            
            //console.log(ids);
            if(ids == ""){
            	layer.msg('请先选择要操作的数据！', {icon: 2,time: 3000});
            	return false;
            }
            rouSynchro(ids);
        });
        
        /**单独同步**/
        $(document).on('click','a[name="rou_synchro_one"]',function(){
        	var ids = $(this).attr('data-id');
        	if(ids == ""){
            	layer.msg('请先选择要操作的数据！', {icon: 2,time: 3000});
            	return false;
            }
        	rouSynchro(ids);
        });
        
        function rouSynchro(ids){       	
        	var loading = null;
        	layer.confirm('确定同步!', {
        			btn: ['确定','取消'] //按钮
        			,skin: 'layui-layer-molv'
        	}, function(){
        	        var data_url = $("#rou_synchro_batch").attr('data-url');
                    var g = $("input[name='g']").val();
                    var url = data_url+'&g='+g;
                    uploading = layer.load(1, {shade: [0.4, '#393D49']});
                    $.ajax({
        	        	type : 'POST',
    			        url : url,
				        data : {'ids':ids},
				        dataType :'JSON',
				        success : function(res){
				        	layer.close(uploading);
				        	if(res.status == 1){
				        		layer.alert(res.msg, {
				        			skin: 'layui-layer-molv' //样式类名
						            ,closeBtn: 0
					            }, function(){
						             window.location.reload();
					            });	
				        		//layer.alert(res.msg, {skin: 'layui-layer-molv'});
					        }else{
					        	layer.close(uploading);
						        layer.alert(res.msg, {icon: 2, skin: 'layui-layer-molv'});
					        }
				        }
			        });
                    
        	    }, function(){
        			//取消
        		});
        }
        
	   
</script>
	
<script>
    $(function(){
       //查看强制性解除的记录
       $(document).on("click", 'a[name="force_view"]', function (e) {
       	    var g = $('input[name="g"]').val();
    		var url = '?r=routineCrossServer/forceView&g='+g;
    		layer.open({
    			skin: 'layui-layer-molv'
    			,type: 2
    			,area: ['900px', '600px']
    			,title:'强制性解除记录'
    			,content: url
    			,btn: ['确定']   			
    		});
       });
       
       
    });
    
    
    
</script>